package com.server;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;

public class LoyaltyPointServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;
		
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		String msg = null;
		String username = req.getParameter("username");

		ConnectDB();
		
		try 
		{
			ReservationHelper.Setup(connection, username);
			CustomerHelper.Setup(connection);
			
			ReservationHelper.UpdateResStatus(username);
			int point = CustomerHelper.GetSelectedCustomer(username).point;
			req.setAttribute("username", username);
			req.setAttribute("point", point);
			
			ArrayList<ReservationInfo> resList = ReservationHelper.GetCompletedResList();
			ArrayList<FlightInfo> flightList = ReservationHelper.GetCompletedFlightList();
			
			if (resList.size() == 0)
			{
				msg = "You do not have any loyalty points to claim.";
				req.setAttribute("msg", msg);
				req.getRequestDispatcher("index_loggedin.jsp").forward(req, resp);			
			}
			else
			{
				req.setAttribute("resList", resList);
				req.setAttribute("flightList", flightList);
				req.getRequestDispatcher("reservation/loyalty_point.jsp").forward(req, resp);
			}
							
		} 
		catch (SQLException e1) 
		{
			e1.printStackTrace();
		}
				
		
	}

}

